package org.example.dfs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author liyishan
 * @date 2023/8/31 09:17
 * @apiNote
 */

public class Test00046Permute {

    public static void main(String[] args) {

    }

    public static List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        for(int num:nums){
            list.add(num);
        }
        dfs(nums, list, res, 0);
        return res;
    }

    public static void dfs(int[] nums, List<Integer> list, List<List<Integer>> res,int index){
        if(index == nums.length){
            res.add(new ArrayList<>(list));
            return;
        }
        for(int i = index;i<nums.length;i++){
            Collections.swap(list, index, i);
            dfs(nums,list,res,index+1);
            Collections.swap(list, index, i);
        }
    }
}
